<?php $db = new Mypdo(); ?>
<?php


if (!empty($_SESSION['login'])&&!empty($_SESSION['email'])){

$chargeManager = new ChargeManager($db);
$charge = $chargeManager->getCharge($_GET['id']);

if(!empty($_GET['supprid'])){
    if($_GET['id'] == $_GET['supprid']){
        $chargeManager->delCharge($_GET['supprid']);
        header('Location: index.php?page=113&id='.$charge->getIdLoc());
    }
}else{

    if(empty($_POST)){

        ?>

        <h1>Modifier une charge</h1>

        <form method="post" action="#">

            <p>
            <h3>Information</h3>

            <label for="nom_charge">Nom de la charge :</label><input name="nom_charge" type="text" id="nom_charge" required="required" value="<?php echo $charge->getNomCharge(); ?>" /><br />
            <label for="montant_charge">Montant :</label><input type="number" name="montant_charge" id="montant_charge" required="required" value="<?php echo $charge->getMontantCharge(); ?>" /><br />
            <label for="tva_charge">Taux Tva % :</label><input type="number" name="tva_charge" id="tva_charge" required="required" value="<?php echo $charge->getTvaCharge(); ?>" /><br />
            <p><input type="reset" value="Annuler" /><input type="submit" value="Valider" /></p>
        </form>
        <input id="suppr" name="suppr" type="button" onclick="document.location.href='index.php?page=118&id=<?php echo $_GET['id']; ?>&supprid=<?php echo $charge->getIdCharge(); ?>'" value="Supprimer" />

    <?php }else{

            $chargeN = new Charge($_POST);
            $chargeN->setIdCharge($_GET['id']);
            $chargeN->setIdLoc($charge->getIdLoc());
            var_dump($chargeN);



            $chargeManager->update($chargeN);

            header('Location: #');

    }
}
}else{
    header('Location: index.php');
}